package com.zzr.demo.redis.controller;

import com.zzr.demo.redis.service.RecorderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicLong;

/**
 * @author: xiaomi
 * @date: 2021/10/10
 * @description:
 */
@RestController
@RequestMapping("recorder/action")
@Api(tags = "记录器：用户行为记录器")
@Slf4j
public class ActionRecorderController {

    @Autowired
    RecorderService recorderService;

    AtomicLong userId = new AtomicLong();


    @GetMapping("/record")
    @ApiOperation("记录某个用户的行为")
    public boolean record() {
        recorderService.recordUser(userId.getAndIncrement());
        return true;
    }


    @GetMapping("/count")
    @ApiOperation("统计执行了行为的用户个数")
    public long count() {
        long count = recorderService.countRecord();
        return count;
    }

}
